package com.zh.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.common.Result;
import com.zh.mapper.StateMapper;
import com.zh.pojo.State;
import com.zh.pojo.StateDetail;
import com.zh.pojo.vo.StateVo;
import com.zh.service.StateDetailService;
import com.zh.service.StateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @Description:
 * @ClassName StateServiceImpl
 * @date: 2021.05.10 14:22
 * @Author: zhanghang
 */
@Service
public class StateServiceImpl extends ServiceImpl<StateMapper,State> implements StateService {

    @Autowired
    private StateDetailService stateDetailService;

    /**
     * description: 根据统计主题id，获取统计的具体项
     * date: 2021年-05月-11日 9:29
     * author: zhanghang
     * 
     * @param id
     * @return com.zh.common.Result<?>
     */ 
    @Override
    public Result<?> getStatesById(Integer id) {
        Result<Object> result = new  Result<Object>();
        StateVo stateVo = new StateVo();
        State state = this.getById(id);
        if (null == state){
            return Result.error("没有找到该专题");
        }
        BeanUtil.copyProperties(state,stateVo);
        List<StateDetail> list = stateDetailService.list(new QueryWrapper<StateDetail>()
                .lambda()
                .eq(StateDetail::getStateId, id)
                .eq(StateDetail::getStatus, 1));
        stateVo.setStateDetailList(list);
        result.setResult(stateVo);
        return result;
    }
}
